package com.battle.service.controller.web;

import com.battle.pojo.param.personWarCase.GetPersonWarCaseListParam;
import com.battle.pojo.param.skillCertificate.*;
import com.battle.pojo.vo.skillCertificate.*;
import com.battle.service.service.in.*;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;

/**
 * web/技能证书
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/skillCertificate/web")
public class SkillCertificateWebController {

    private final SkillCertificateService service;

    public SkillCertificateWebController(SkillCertificateService service) {
        this.service = service;
    }


    /**
     * 创建技能证书
     *
     * @param param
     * @return
     */
    @PostMapping("/createSkillCertificate")
    public ApiResult createSkillCertificate(@RequestBody @Valid CreateSkillCertificateParam param) {
        service.createSkillCertificate(param);
        return ApiResult.ok();
    }


    /**
     * 修改技能证书
     *
     * @param param
     */
    @PutMapping("/editSkillCertificate")
    public ApiResult editSkillCertificate(@RequestBody @Valid EditSkillCertificateParam param) {
        service.editSkillCertificate(param);
        return ApiResult.ok();
    }

    /**
     * 移除技能证书
     *
     * @param id
     */
    @DeleteMapping("/removeSkillCertificate")
    public ApiResult removeSkillCertificate(@RequestParam("id") Long id) {
        service.removeSkillCertificate(id);
        return ApiResult.ok();
    }

    /**
     * 批量更新-数据加密
     * @return
     */
    @PostMapping("/bathUpdate")
    public ApiResult bathUpdate() {
        service.bathUpdate();
        return ApiResult.ok();
    }

    /**
     * 获取技能证书详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getSkillCertificate")
    public ApiResult<GetSkillCertificateVo> getSkillCertificate(@RequestParam("id") Long id) {
        GetSkillCertificateVo vo = service.getSkillCertificate(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取技能证书列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getSkillCertificateList")
    public ApiResult<PageResult<GetSkillCertificateListVo>> getSkillCertificateList(@RequestBody GetSkillCertificateListParam param) {
        PageResult<GetSkillCertificateListVo> result = service.getSkillCertificateList(param);
        return ApiResult.ok(result);
    }

    /**
     * 导出技能证书
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportSkillCertificateList")
    public void exportSkillCertificateList(HttpServletResponse response, @RequestBody GetSkillCertificateListParam param) {
        try {
            service.export(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }

}

